<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$query = "select * from `news` where `user_id` = '".$user->getUserId()."' order by `news_id` desc";
$news_list = $db->getTable($query);

$page = UV::readInt(strip_tags($route->GET("page")));
$limit = 10;
$count = count($news_list);
$max_page = ceil($count / $limit);
if ($page < 1)
	$page = 1;
elseif ($page > $max_page)
	$page = $max_page;

$query .= " limit ".($page-1)*$limit.",$limit";
$news_list = $db->getTable($query);

require_once CABINET.DS."head.php";
?>

<div class="full">
	<div class="submenu_container">
		<a class="submenu_button all_news submenu_button_active" href='/cabinet/news/list'>Список новостей</a>
		<a class="submenu_button add_news" href='/cabinet/news/add'>Добавить новость</a>
	</div>
	<h3>Список новостей</h3>
	<?php
		foreach ($news_list as $news_item){
			?><div class="moderationrecord">
				<div class="recorddate left" style='width:75px'><?php echo date("d.m.Y",$news_item['time']); ?></div>
				<div class="record left">
					<div class="recordtitle"><?php echo "<a target='_blank' href='/news/".$news_item['news_id']."-".translitIt($news_item['title'])."'>".$news_item['title']."</a>"; ?></div>
					<div class="recordtext"><?php echo strip_tags($news_item['preview']); ?></div>
				</div>
				<div class="recordbuttons right">
					<a class="moder_buttons redit" href="/cabinet/news/edit/<?php echo $news_item['news_id']; ?>"></a>
					<a class="moder_buttons rdelete" href="/cabinet/news/delete/<?php echo $news_item['news_id']; ?>"></a>
				</div>
			</div><?php
		}
		echo showPages($count,$limit);
	?>
</div>

<?php require_once CABINET.DS."footer.php"; ?>
